﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyLib
{
    public class CacheHelper
    {
        public delegate bool CacheGetter<TData>(out TData data);

        public static TData Get<TData>(CacheGetter<TData> cacheGetter, Func<TData> sourceGetter, Action<TData> cacheSetter)
        {
            TData data;
            if(cacheGetter(out data))
            {
                return data;
            }

            data = sourceGetter();
            cacheSetter(data);

            return data;
        }
    }
}
